package cn.fintecher.pangolin.service.report.web;

import cn.fintecher.pangolin.common.web.BaseController;
import cn.fintecher.pangolin.entity.elastic.BehavioralProcess;
import cn.fintecher.pangolin.entity.elastic.DailyCollectionStatisticsRecord;
import cn.fintecher.pangolin.entity.elastic.PrincipalPayment;
import cn.fintecher.pangolin.entity.elastic.UserPayment;
import cn.fintecher.pangolin.service.report.request.DailyCollectionStatisticsRequest;
import cn.fintecher.pangolin.service.report.request.ReportRequest;
import cn.fintecher.pangolin.service.report.scheduled.DailyCollectionStatisticsScheduled;
import cn.fintecher.pangolin.service.report.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: xiaqun
 * @Description: 报表相关接口
 * @Date: 9:11 2019/12/11
 */

@RestController
@RequestMapping("/api/reportController")
@Api(value = "报表相关接口", description = "报表相关接口")
public class ReportController extends BaseController {
    @Autowired
    private ReportService reportService;

    /**
     * 查询行为过程监控表
     */
    @ApiOperation(value = "查询行为过程监控表", notes = "查询行为过程监控表")
    @GetMapping("/getBehavioralProcess")
    public ResponseEntity<List<BehavioralProcess>> getBehavioralProcess(ReportRequest request,
                                                                        @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to get behavioral process,{}", request);
        List<BehavioralProcess> list = reportService.getBehavioralProcess(request, token);
        return ResponseEntity.ok().body(list);
    }

    /**
     * 查询委托方回款报表
     */
    @ApiOperation(value = "查询委托方回款报表", notes = "查询委托方回款报表")
    @GetMapping("/getPrincipalPayment")
    public ResponseEntity<List<PrincipalPayment>> getPrincipalPayment(ReportRequest request) {
        log.info("REST request to get principal payment,{}", request);
        List<PrincipalPayment> list = reportService.getPrincipalPayment(request);
        return ResponseEntity.ok().body(list);
    }

    /**
     * 导出行为过程监控表
     */
    @ApiOperation(value = "导出行为过程监控表", notes = "导出行为过程监控表")
    @GetMapping("/exportBehavioralProcess")
    public ResponseEntity<Void> exportBehavioralProcess(ReportRequest request,
                                                        @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to export behavioral process,{}", request);
        reportService.exportBehavioralProcess(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 导出委托方回款报表
     */
    @ApiOperation(value = "导出委托方回款报表", notes = "导出委托方回款报表")
    @GetMapping("/exportPrincipalPayment")
    public ResponseEntity<Void> exportPrincipalPayment(ReportRequest request,
                                                       @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to export principal payment,{}", request);
        reportService.exportPrincipalPayment(request, token);
        return ResponseEntity.ok().build();
    }

    @ApiOperation(value = "每日催收统计", notes = "每日催收统计")
    @GetMapping("/dailyCollectionStatistics")
    public ResponseEntity<List<DailyCollectionStatisticsRecord>> dailyCollectionStatistics(DailyCollectionStatisticsRequest request, @RequestHeader(value = "X-UserToken") String token) {
        List<DailyCollectionStatisticsRecord> dailyCollectionStatisticsRecords = reportService.dailyCollectionStatistics(request);
        return ResponseEntity.ok().body(dailyCollectionStatisticsRecords);
    }


    @ApiOperation(value = "导出每日催收统计", notes = "导出每日催收统计")
    @GetMapping("/exportDailyStatistics")
    public ResponseEntity<Void> exportDailyStatistics(DailyCollectionStatisticsRequest request, @RequestHeader(value = "X-UserToken") String token) {
        reportService.exportDailyStatistics(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询催收员回款报表
     */
    @ApiOperation(value = "查询催收员回款报表", notes = "查询催收员回款报表")
    @GetMapping("/getUserPayment")
    public ResponseEntity<List<UserPayment>> getUserPayment(ReportRequest request,
                                                            @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to get user payment,{}", request);
        List<UserPayment> list = reportService.getUserPayment(request, token);
        return ResponseEntity.ok().body(list);
    }

    /**
     * 导出催收员回款报表
     */
    @ApiOperation(value = "导出催收员回款报表", notes = "导出催收员回款报表")
    @GetMapping("/exportUserPayment")
    public ResponseEntity<Void> exportUserPayment(ReportRequest request,
                                                  @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to export user payment,{}", request);
        reportService.exportUserPayment(request, token);
        return ResponseEntity.ok().build();
    }

}
